package org.yyjkcache.common;

import java.io.IOException;
import java.io.InputStream;

public class FileReader extends FileBase {

	public String readUTF(String path) {
		InputStream inStream = getInputStream(path);

		return readStream(inStream);
	}

	public String readUTF(InputStream ins) throws IOException {
		return readStream(ins);
	}
	/**
	 * 读取流
	 * @param ins 输入流
	 * @return
	 */
	public String readStream(InputStream ins) {
		byte b[] = new byte[1024 * 4];
		int len = 0;
		StringBuilder builder = new StringBuilder();
		try {
			while ((len = ins.read(b)) != -1) {
				ins.read(b, 0, len);
				builder.append(new String(b, "UTF-8"));
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (ins != null) {
				try {
					ins.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return builder.toString().trim();
	}
}
